<?php

namespace common\models\Fenhuigrade;

use Yii;
use yii\behaviors\TimestampBehavior;
/**
 * This is the model class for table "fenhuigrade".
 *
 * @property integer $id
 * @property string $name
 * @property integer $status
 * @property integer $created_at
 * @property integer $updated_at
 */
class Fenhuigrade extends \yii\db\ActiveRecord
{
    private $_statusLabel;
    const STATUS_DELETED = 0; //再审核
    const STATUS_ACTIVE = 10; //y
    const STATUS_SUCCESS = 20; //已审核
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'fenhuigrade';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['name'], 'required'],
            [['content'], 'string'],
            [['status', 'created_at', 'updated_at'], 'integer'],
            [['name', 'label_img'], 'string', 'max' => 255],
            [['name'], 'unique'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => Yii::t('app', 'ID'),
            'name' => Yii::t('app', 'Name'),
            'status' => Yii::t('app', 'Status'),
            'created_at' => Yii::t('app', 'Created At'),
            'updated_at' => Yii::t('app', 'Updated At'),
            'label_img' => Yii::t('app', '封面图片'),
            'content' => Yii::t('app', '内容'),
        ];
    }
    public function getStatusLabel()
    {
        if ($this->_statusLabel === null) {
            $statuses = self::getArrayStatus();
            $this->_statusLabel = array_key_exists($this->status,self::getArrayStatus()) ? $statuses[$this->status] : '无';
        }
        return $this->_statusLabel;
    }
    /**
     * @inheritdoc
     */
    public static function getArrayStatus()
    {
        return [
            self::STATUS_ACTIVE => Yii::t('app', 'STATUS_ACTIVE'),
            self::STATUS_DELETED => Yii::t('app', 'STATUS_INACTIVE'),

        ];
    }
    //自动获取时间
    public function behaviors()
    {
        return [
            TimestampBehavior::className(),
        ];
    }
}
